Skip to content

Read aaa, aaaa and e in number formats as date codes - #1081

Open
vtxe02023274 wants to merge 1 commit into
mini-software:masterfrom
vtxe02023274:fix/weekday-era-date-formats
Open

vtxe02023274 wants to merge 1 commit into
mini-software:masterfrom
vtxe02023274:fix/weekday-era-date-formats

Conversation

@vtxe02023274

@vtxe02023274 vtxe02023274 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

aaa and aaaa (short and long day of the week) and e (year of the era, the ROC year in a Taiwan workbook, the era year in a Japanese one) are date codes in Excel, but the format tokenizer has no rule for them. a and e are reserved characters, so they are not read as literals either, and the whole format is a syntax error. Common formats such as m/d (aaa), yyyy/m/d aaaa, e/m/d and [$-411]ge.m.d are therefore not date formats, and Query returns the serial number (45306) instead of the DateTime.

Excel 365 with the value 45306.25:

Format Excel shows
aaa 週一
m/d (aaa) 1/15 (週一)
aaaa h:mm 星期一 6:00
e/m/d 113/1/15
[$-411]ge.m.d R6.1.15

ReadToken now reads a run of e and a run of three or more a as tokens, and IsDatePart counts them as date parts. e+ and e- are still read first, so 0.00E+00 stays a number format. A single a or aa is not a code (Excel saves it as \a), so it is left as before.

As a side effect IsValid is now true for these formats, so SheetStyleFormatsCache keeps them on export instead of dropping them.

Tests in MiniExcelGithubIssuesTests:

  • TestDateFormatWithWeekdayOrEraYear: the formats above are date formats; 0.00E+00, ##0.0e-0, 0 \a and 0 "aaa" are not
  • TestQueryDateWithWeekdayOrEraYearFormat: a ClosedXML workbook with four of these formats reads back as DateTime

Both fail on master and pass with this change. tests/MiniExcel.OpenXml.Tests (574 tests) and tests/MiniExcel.Csv.Tests pass on net8.0, net10.0 and net11.0, and src/MiniExcel.OpenXml builds for all targets including netstandard2.0. I did not have a net9.0 runtime here.

Summary by CodeRabbit

  • Bug Fixes
    • Improved recognition of spreadsheet date formats that include weekday names, including abbreviated and full weekday tokens in either letter case.
    • Improved handling of Japanese era-year formats.
    • Queries now return the original date and time values for cells using these weekday and era-year formats.
    • Scientific notation and quoted or escaped text are not incorrectly treated as date formats.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The number-format parser now recognizes weekday tokens with three or more consecutive a or A characters as date parts. Tests cover weekday and era-year format classification, exclusions, and querying cells with those formats.

Changes: Weekday date formats

Layer / File(s) Summary
Token recognition and date-query validation
src/MiniExcel.OpenXml/Utils/OpenXmlNumberFormatHelper.cs, tests/MiniExcel.OpenXml.Tests/Issues/MiniExcelGithubIssuesTests.cs
The parser recognizes qualifying weekday tokens and classifies them as date parts. Tests cover weekday and era-year formats, exclusions, and querying values formatted with weekday or era-year tokens.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: shps951023, michelebastione

Merge Risk: Minimal · up to 5999c

This change makes weekday and era-year number formats return dates instead of serial numbers. It is narrowly scoped, has targeted tests, and I see no merge-blocking risk. The failing CI job concerns reviewer assignment configuration, not the code.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: the number format reader now treats the aaa, aaaa, and e format codes as date codes. The raw summary confirms the tokenizer change in OpenXmlNumberFormatHelper.cs (ru…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: the number format reader now treats the aaa, aaaa, and e format codes as date codes. The raw summary confirms the tokenizer change in OpenXmlNumberFormatHelper.cs (runs of a or A with three or more characters, and aaa-prefixed tokens classified as date parts). The PR objectives describe the same change, including the e run handling. The title matches the main change, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 428f3f92-5101-4eac-8c55-76d3c523bf8e
Commits

Reviewing files that changed from the base of the PR and between ffc3059 and 5999cb7.

Files selected for processing: 2

  • src/MiniExcel.OpenXml/Utils/OpenXmlNumberFormatHelper.cs
  • tests/MiniExcel.OpenXml.Tests/Issues/MiniExcelGithubIssuesTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant